// MIT License
// 开源地址：https://gitee.com/co1024/AbcMvc
// Copyright (c) 2021-2023 1024
// Abc.Mvc=Furion+EF+SqlSugar+Pear layui admin.

namespace Abc.Web.Mvc.Areas.HtAdmin.Controllers;

[MaMvc("HtAdmin", controllerDescription: "系统设置", PCode = "HtAdmin_System")]
public class SysSettingController : HtAdminBaseController
{
    private readonly IDataConfigService _dataConfigService;
    private readonly ILogger<UserController> _logger;

    public SysSettingController(ILogger<UserController> logger
        , IDataConfigService dataConfigService)
    {
        _logger = logger;
        _dataConfigService = dataConfigService;
    }

    //[MaMenu(name: "设置页面", CreateDate = "2021-07-22")]
    //[MaPermission(name: "权限列表", actions: "Index,GetList")]
    public IActionResult Index()
    {
        return View();
    }

    /// <summary>
    ///     系统设置
    /// </summary>
    /// <returns></returns>
    [MaMenu("系统设置", CreateDate = "2021-07-31")]
    [MaPermission("系统设置", "SystemSetting,ImgUpload,FileUpload")]
    [HttpGet]
    public async Task<IActionResult> SystemSetting()
    {
        var model = await _dataConfigService.GetSetting<SysSettingDto>(DataConfigDtoType.SysSetting);
        return View(model);
    }

    [HttpPost]
    public async Task<JsonResult> SystemSetting(SysSettingDto input)
    {
        await _dataConfigService.AddOrUpdateSetting(input, DataConfigDtoType.SysSetting);
        return Json("");
    }

    /// <summary>
    ///     图片上传
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    [MaPermission("图片上传", "ImgUpload")]
    [HttpPost]
    [IgnoreAntiforgeryToken]
    public async Task<JsonResult> ImgUpload(string type)
    {
        var uploadresult = await WebUpLoad.FileUpload(new WebUploadInput(FloderName: type));
        return Json(uploadresult.GetDefaultResult());
    }

    /// <summary>
    ///     文件上传
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    [MaPermission("文件上传", "FileUpload")]
    [HttpPost]
    [IgnoreAntiforgeryToken]
    public async Task<JsonResult> FileUpload(string type)
    {
        var uploadresult = await WebUpLoad.FileUpload(new WebUploadInput(FloderName: type));
        return Json(uploadresult.GetDefaultResult());
    }
}